1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
164.
165.
166.
167.
168.
169.
170.
171.
172.
173.
174.
175.
176.
177.
178.
179.
180.
181.
182.
183.
184.
185.
186.
187.
188.
189.
190.
191.
192.
193.
194.
195.
196.
197.
198.
199.
200.
201.
202.
203.
204.
205.
206.
207.
208.
209.
210.
211.
212.
213.
214.
215.
216.
217.
218.
219.
220.
221.
222.
223.
224.
225.
226.
227.
228.
229.
230.
231.
232.
233.
234.
235.
236.
237.
238.
239.
240.
241.
242.
243.
244.
245.
246.
247.
248.
249.
250.
251.
252.
253.
254.
255.
256.
257.
258.
259.
260.
261.
262.
263.
264.
265.
266.
267.
268.
269.
270.
271.
272.
273.
274.
275.
276.
277.
278.
279.
280.
281.
282.
283.
284.
285.
286.
287.
288.
289.
290.
291.
292.
293.
294.
295.
296.
297.
298.
299.
300.
301.
302.
303.
304.
305.
306.
307.
308.
309.
310.
311.
312.
313.
314.
315.
316.
317.
318.
319.
320.
321.
322.
323.
324.
325.
326.
327.
328.
329.
330.
331.
332.
333.
334.
335.
336.
337.
338.
339.
340.
341.
342.
343.
344.
345.
346.
347.
348.
349.
350.
351.
352.
353.
354.
355.
356.
357.
358.
359.
360.
361.
362.
363.
364.
365.
366.
367.
368.
369.
370.
371.
372.
373.
374.
375.
376.
377.
378.
379.
380.
381.
382.
383.
384.
385.
386.
387.
388.
389.
390.
391.
392.
393.
394.
395.
396.
397.
398.
399.
400.
401.
402.
403.
404.
405.
406.
407.
408.
409.
410.
411.
412.
413.
414.
415.
416.
417.
418.
419.
420.
421.
422.
423.
424.
425.
426.
427.
428.
429.
430.
431.
432.
433.
434.
435.
436.
437.
var dvjh = (function($){
var _objImgRatio = {
border: [1, 1, 1, 1],
padding: [0, 0, 0, 0]
},
_objTourne = {
options: {
degrees: 0,
debug: true
},
avecStyle: function(self, matrix){
self.attr("style", "-moz-transform:" + matrix +
"; -webkit-transform:" + matrix +
"; -ms-transform:" + matrix +
"; -o-transform:" + matrix +
"; transform:" + matrix +
";");
},
setDegrees: function(self, value){
var v = parseInt(value, 10) || 0;
if (v != _objTourne.options.degrees){
this.options.degrees = v;
var rad = v * Math.PI * 2.0 / 360.0,
costheta = Math.cos(rad),
sintheta = Math.sin(rad),
a = parseFloat(costheta, 10).toFixed(8),
c = parseFloat(-sintheta, 10).toFixed(8),
b = parseFloat(sintheta, 10).toFixed(8),
d = parseFloat(costheta, 10).toFixed(8),
matrix = "matrix(" + a + ", " + b + ", " + c + ", " + d + ", 0, 0);";
this.avecStyle(self, matrix);
var optionsChangedEvent = new $.Event("optionsChanged.dvjhTourne");
optionsChangedEvent.dvjh = {
initiateur: self,
optionsKey: "degrees",
optionsValue: v
};
self.trigger(optionsChangedEvent);
}
}
},
_objTooltip = {
xOffset: 10,
yOffset: -20,
needClass: "tooltip",
width: "20rem",
height: "auto",
color: "black",
backgroundColor: "#FFFFE0",
backgroundImage: "none",
fontFamily: "sans-serif",
fontStyle: "italic",
fontSize: "1.0rem",
fontWeight: "normal",
lineHeight: "1.3rem",
textMargin: "0.6rem",
textBorder: "none",
border: "0.1rem solid #777777",
mozBoxShadow: "#000000 0rem 0.4rem 1rem -0.5rem",
mozBorderRadius: "0.4rem",
webkitBoxShadow: "0rem 0.2rem 0.4rem #999999",
webkitBorderRadius: "0.5rem"
},
_objNotify = {
position:"bottomRight",
top: "20px",
left: "20px",
bottom: "auto",
right: "auto",
width: "250px",
height: "auto",
color: "black",
backgroundColor: "#FFFFE0",
backgroundImage: "none",
fontFamily: "sans-serif",
fontStyle: "italic",
fontSize: "0.8em",
fontWeight: "normal",
lineHeight: "1.3em",
textHTML: " ",
textMargin: "6px",
border: "1px solid #777777",
mozBoxShadow: "#000000 0px 4px 10px -5px",
mozBorderRadius: "4px",
webkitBoxShadow: "0px 2px 4px #999999",
webkitBorderRadius: "5px",
callback: "rien",
boolBtn: true,
delay: 30000,
fading: true,
fadeIn: 1000,
fadeOut: 1000,
imgFloat: "left",
imgSrc: "rien",
imgWidth: "50px",
imgHeight: "40px",
imgBorder: "1px solid grey"
};
$.extend( $.fn, {
remove: function(){
var removeEvent = new $.Event("remove.dvjh");
removeEvent.dvjh = {
"infos": 'déclenchement d\'un événement "remove.dvjh" lors de la suppression d\'un élément',
"initiateur": "Espace de nom dvjh",
"usage": 'Exemple : $(selector).on("remove.dvjh", function(event){...}).remove();',
"version": "v1.0.0 2011-10-18"
};
this.trigger(removeEvent);
return jQuery.fn.remove.apply( this, arguments );
},
imgRatio: function(options){
var opts = $.extend(true, {}, _objImgRatio, options);
return this.each(function(i, item){
var photo = $(item),
ratio = photo.data("ratio"),
photoParent = photo.parent(),
photoParentWidth = photoParent.innerWidth() - opts.border[1]
- opts.border[3] - opts.padding[1] - opts.padding[3],
photoParentHeight = photoParent.innerHeight() - opts.border[0]
- opts.border[2] - opts.padding[0] - opts.padding[2],
w = photoParentWidth,
h = w/ratio;
if (h > photoParentHeight){
h = photoParentHeight;
w = h*ratio;
}
photo.css({width: w, height: h});
});
},
tourne: function(options){
var self = this;
if (_objTourne.options.debug){
self.bind("optionsChanged.dvjhTourne", function(event){
var obj = event.dvjh,
el = obj.initiateur[0];
console.log("L'option " +
obj.optionsKey +
" a pris la valeur " +
obj.optionsValue +
" le " +
new Date(event.timeStamp).toLocaleString() +
" a la demande de l'élément " +
el.tagName +
" , ID = " +
el.id +
" , Class = " +
el.className);
});
}
if (options != undefined){
$.each(options, function(key, value){
self.tourneSetOptions(key, value);
});
} else {
self.tourneSetOptions("degrees", "45");
}
return this;
},
tourneSetOptions: function(key, value){
switch(key){
case "degrees":
_objTourne.setDegrees(this, value);
break;
default:
throw "L'option " + key + " n'existe pas";
};
return this;
},
tourneGetOptions: function(key){
switch(key){
case "degrees":
return _objTourne.options.degrees;
break;
default:
throw "L'option " + key + " n'existe pas";
};
return this;
},
tooltip: function(options){
var opts = $.extend(true, {}, _objTooltip, options);
return this.each(function(i, item){
if (($(item).hasClass(opts.needClass)) && ($(item).attr("title") != "")) {
$(item).mouseenter(function(e){
var obj = $(this);
obj.data("tooltip", {
title: obj.attr("title"),
cursor: obj.css("cursor")
});
obj.attr("title", "").css("cursor","help");
$("<div/>", {
id: "tooltip",
html: "<div style='margin:" +
opts.textMargin + ";" + opts.textBorder + ";'>" +
obj.data("tooltip").title + "</div>",
css:{
position: "absolute",
display: "block",
top: (e.pageY - opts.yOffset) + "px",
left: (e.pageX + opts.xOffset) + "px",
width: opts.width,
height: opts.height,
color: opts.color,
backgroundColor: opts.backgroundColor,
backgroundImage: opts.backgroundImage,
fontFamily: opts.fontFamily,
fontStyle: opts.fontStyle,
fontSize: opts.fontSize,
fontWeight: opts.fontWeight,
lineHeight: opts.lineHeight,
zIndex: "9999",
border: opts.border,
"-moz-box-shadow": opts.mozBoxShadow,
"-moz-border-radius": opts.mozBorderRadius,
"-webkit-box-shadow": opts.webkitBoxShadow,
"-webkit-border-radius": opts.webkitBorderRadius
}
}).appendTo("body");
});
$(item).mouseleave(function(){
$(this).attr("title", $(this).data("tooltip").title).css("cursor", $(this).data("tooltip").cursor);
$("#tooltip").remove();
});
$(item).mousemove(function(e){
var haut = e.pageY - opts.yOffset;
var gauche = e.pageX + opts.xOffset;
if (($(window).height() + $(document).scrollTop() - e.pageY) < ($("#tooltip").outerHeight() + 30)){
haut -= $("#tooltip").outerHeight() + 50;
}
if (($(window).width() + $(document).scrollLeft() - e.pageX) < ($("#tooltip").outerWidth() + 15)){
gauche -= $("#tooltip").outerWidth() + 15;
}
$("#tooltip").css({
top: haut + "px",
left: gauche + "px"
});
});
$(item).click(function(){
$(this).mouseleave();
});
}
});
}
});
$.notify = function(options){
var opts = $.extend(true, {}, _objNotify, options);
if (opts.position == "bottomRight"){
opts.top = "auto";
opts.left = "auto";
opts.bottom = "20px";
opts.right = "20px";
} else if (opts.position == "bottomLeft"){
opts.top = "auto";
opts.left = "20px";
opts.bottom = "20px";
opts.right = "auto";
} else if (opts.position == "topLeft"){
opts.top = "20px";
opts.left = "20px";
opts.bottom = "auto";
opts.right = "auto";
} else if (opts.position == "topRight"){
opts.top = "20px";
opts.left = "auto";
opts.bottom = "auto";
opts.right = "20px";
}
var btnOK = $("<div/>", {
html:"<button type='button'>OK</button>",
css:{
clear:"both",
display:"block",
margin:"6px",
textAlign:"center"
}
});
var divNotify = $("<div/>", {
id: "notify" + new Date().getTime(),
html: function(){
var imgStr = "";
if (opts.imgSrc != "rien"){
if (opts.imgFloat == "left") {
imgStr = "<img src='" + opts.imgSrc +
"' style='float:" + opts.imgFloat +
";width:" + opts.imgWidth +
";height:" + opts.imgHeight +
";border:" + opts.imgBorder +
";margin-right:6px;margin-bottom:6px;'/>";
} else {
imgStr = "<img src='" + opts.imgSrc +
"' style='float:" + opts.imgFloat +
";width:" + opts.imgWidth +
";height:" + opts.imgHeight +
";border:" + opts.imgBorder +
";margin-left:6px;margin-bottom:6px;'/>";
}
}
var str = "<div style='margin:" + opts.textMargin + ";'>" +
imgStr + opts.textHTML +
"</div>";
return str;
},
css:{
position:"fixed",
display: opts.fading ? "none" : "block",
top: opts.top,
left: opts.left,
bottom: opts.bottom,
right: opts.right,
width: opts.width,
height: opts.height,
color: opts.color,
backgroundColor: opts.backgroundColor,
backgroundImage: opts.backgroundImage,
fontFamily: opts.fontFamily,
fontStyle: opts.fontStyle,
fontSize: opts.fontSize,
fontWeight: opts.fontWeight,
lineHeight: opts.lineHeight,
zIndex: "9999",
border: opts.border,
"-moz-box-shadow": opts.mozBoxShadow,
"-moz-border-radius": opts.mozBorderRadius,
"-webkit-box-shadow": opts.webkitBoxShadow,
"-webkit-border-radius": opts.webkitBorderRadius
},
click: function(e){
if (opts.fading){
$(this).fadeOut(parseInt(opts.fadeOut), function(){
$(this).remove();
});
} else {
$(this).remove();
}
if (opts.callback != "rien") opts.callback(e);
return false;
}
});
if (opts.boolBtn){
$(divNotify).append(btnOK).appendTo("body");
} else {
$(divNotify).appendTo("body");
}
if (opts.fading){
$(divNotify).fadeIn(parseInt(opts.fadeIn));
}
if (opts.delay >= 5000) {
window.setTimeout(function(){ $(divNotify).click(); }, parseInt(opts.delay));
}
};
$(function(){
$("*", "body").tooltip();
});
return {
"$": $,
"remove": function(selector){
$(selector).on("remove.dvjh", function(event){
$.each(event.dvjh, function(key, value){
console.log( key, " : ", value );
});
$.each(event, function(key, value){
if (!$.isFunction(value)){
if (key === "timeStamp"){
console.log( key, " : ", new Date(value).toLocaleString() );
} else {
console.log( key, " : ", value );
}
}
});
}).remove();
}
};
})(jQuery.sub());